from time import time, ctime, strftime, localtime

import shore


# TODO:2009-06-04:damosurfer: Add some sort of cleaning up function
#

def temp_file():
    todate = 'recovery_files/%s.tmp' % strftime('%Y.%m.%d_%H%M', localtime())
    tf = open(todate, 'w')
    tf.write('# CLAMS recovery file. \xc2\xa9 2009, Dami\xc3\xa1n Cirelli.\n')
    tf.write('# %s\n#\n' % ctime(time()))
    tf.write('leaf, timestamp, width, length, area\n')
    return tf


def set_pickle_name(name):
    print 'Not implemented'


def log_and_pickle(name, mode='w'):
    lf = open(name, mode)
    # pickle name formation is fullpath/.filename_clam.pkl
    full_path = shore.path_and_base(lf, 'full_path') or '.'
    file_name = shore.path_and_base(lf, 'file_name').rstrip('.csv')
    ext = 'pkl'
    pn = '%s/.%s_clam.%s' % (full_path, file_name, ext)
    return (lf, pn)


logfile = None
pickle_ = None
tempfile = temp_file()
